import App from './App'
import Vue from 'vue'
import store from './store'
import { toast } from './utils/tools'
import uview from "uview-ui"
import './uni.promisify.adaptor'
import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom', cuCustom)

wx.cloud.init({
	env: 'cloud1-2g67qrjjca1d7b80',
	traceUser: true
})

Vue.prototype.$db = wx.cloud.database({ env: 'cloud1-2g67qrjjca1d7b80' })
let mpShare = require('uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare)


Vue.prototype.$toast = toast
Vue.config.productionTip = false
Vue.use(uview)

Vue.filter('formatDate', function(value, format = 'YYYY-MM-DD') {
    if (value === null) return '无';
    if (value === undefined) return '-';
    const date = new Date(value);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');
    switch (format) {
        case 'YYYY-MM-DD':
            return `${year}-${month}-${day}`;
        case 'YYYY-MM-DD HH:MM:SS':
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        default:
            return `${year}-${month}-${day}`; // 默认返回精确到天
    }
});


Vue.prototype.$uploadPic = async (photo) => {
	uni.showLoading({
		mask: true,
		title: '正在上传'
	})
	const picInfo = await uni.getImageInfo({
		src: photo
	})
	let cloudPath = picInfo.path.split('/')
	cloudPath = cloudPath[cloudPath.length - 1]
	const res = await wx.cloud.uploadFile({
		cloudPath,
		filePath: photo
	})
	uni.hideLoading()
	return res.fileID
}
App.mpType = 'app'
const app = new Vue({
	...App,
	store
})
app.$mount()